package com.middleware.mvc.handlerAdapter;


import com.middleware.spring.context.ApplicationContext;
import org.reflections.Reflections;

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLDecoder;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;

public class HandlerAdapterScan {

    // 需要添加依赖: org.reflections:reflections:0.10.2
    public List<HandlerAdapter> getHandlerAdapters() {
        List<HandlerAdapter> handlers = new ArrayList<>();
        String basePackage = HandlerAdapterScan.class.getPackage().getName();

        Reflections reflections = new Reflections(basePackage);
        Set<Class<? extends HandlerAdapter>> adapterClasses =
                reflections.getSubTypesOf(HandlerAdapter.class);

        for (Class<? extends HandlerAdapter> clazz : adapterClasses) {
            try {
                if (!clazz.isInterface()) {
                    handlers.add(clazz.getDeclaredConstructor().newInstance());
                }
            } catch (Exception e) {
                System.err.println("实例化HandlerAdapter失败: " + clazz.getName());
            }
        }
        return handlers;
    }
}
